package cn.alcatraz.mq_03_oneway;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @Description: 消费者
 * @Author: Alcatraz
 * @Version: 1.0
 * @Date:  2022/7/26 21:09
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        // 创建生产者
        DefaultMQProducer oneway_producer_group = new DefaultMQProducer("oneway_producer_group");

        // 连接nameserver
        oneway_producer_group.setNamesrvAddr("127.0.0.1:9876");

        // 启动生产者
        oneway_producer_group.start();

        // 发送单向消息
        Message message = new Message("oneway_topic", "oneway", "测试单向消息".getBytes(StandardCharsets.UTF_8));
        oneway_producer_group.sendOneway(message);

        oneway_producer_group.shutdown();
    }
}
